use axum::{
    response::Redirect,
    routing::get,
    Router,
};

use crate::app_state::AppState;
use tower_http::services::ServeDir;
use tower_http::trace::TraceLayer;
use std::sync::Arc;

mod auth;
mod songs;
mod users;
mod playlist;
mod common;
mod song_comments;
mod user_favorites;

pub fn init_routes(app_state:Arc<AppState>) -> Router
{
    let serve = ServeDir::new("./frontend/dist");
    Router::new()
        .nest_service("/static", serve)
        .fallback(common::handle_404)
        .layer(TraceLayer::new_for_http())
        .route("/", get(|| async { Redirect::to("/static") }))
        .nest("/api", auth::routes(app_state.clone()))
        .nest("/api/songs", songs::routes(app_state.clone()))  
        .nest("/api/users", users::routes(app_state.clone()))
        .nest("/api/playlist", playlist::routes(app_state.clone()))
        .nest("/api/song_comments", song_comments::routes(app_state.clone()))
        .nest("/api/user_favorites", user_favorites::routes(app_state.clone()))
}
